import Ember from 'ember';

export default Ember.Controller.extend({
    queryCondition:'',
    addNewPlan:false,
    mainController: Ember.inject.controller('business.mainpage'),
    statusService: Ember.inject.service("current-status"),
    customerList:Ember.computed("planList",'projectList',function(){
        let projectList = this.get('projectList');
        let planList = this.get('planList');
        let list = new Ember.A();
        let hasCustomer = new Ember.A();
        projectList.forEach(function(project){
          if(!planList.findBy('customer.id',project.get('customer.id'))){
            list.pushObject(project.get('customer'));
          }

        });

        return list;
    }),
    actions:{
      //添加新计划
      addPlan(){
        this.set('addNewPlan',true);
      },
      //选择客户
      selectCustomer(customer){
        this.set('customer',customer);
      },
      //弹窗取消
      invitation(){
        this.set('addNewPlan',false);
      },
      //保存新的护理计划
      saveNewPlan(){
        var _self=this;
        var curUser = this.get("statusService").getUser();
        var newPlan=this.store.createRecord('nursingplan',{});
        newPlan.set('customer',this.get('customer'));
        newPlan.set('createUser',curUser);
        newPlan.set('delStatus',1);
        newPlan.save().then(function(newPro){
          _self.set('addNewPlan',false);
          _self.get("mainController").switchMainPage('nursingplan-detail',{editMode:"add",id:newPlan.get('id')});
        });
      },
      //跳转至编辑页
      toDetailPage(plan){
        let id=plan.get('id');
        this.get("mainController").switchMainPage('nursingplan-detail',{id:id,editMode:"edit"});
      },
    }

});
